﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using OpenComposite.EII.Repository;
using System.ComponentModel;
using OpenComposite.Base.Collections;
using System.Diagnostics;
using OpenComposite.Repository.Properties;
using System.Data;

namespace OpenComposite.EII.Controls
{
	public class UsingHierarchyTreeView : RepositoryHierarchyTreeView
	{
		//#region Constants
		//protected override const string sBusinessObjectFolder = "Business Objects";
		//protected override const string sCapabilitiesFolder = "Capabilities";
		//protected override const string sRulesFolder = "Rules";
		//protected override const string sProcessesFolder = "(internal only) Processes";
		//protected override const string sProcessesMashupFolder = "Mashups";
		//protected override const string sProcessesBPFolder = "Business Processes";
		//protected override const string sProcessesCompositeFolder = "Composites";
		//protected override const string sLogicalMethodsFolder = "LogicalMethods";
		//protected override const string sProcessInterface = "Process Interface";
		//protected override const string sHumandActivitiesFolder = "Human Activities";
		//protected override const string sWebServicesFolder = "Web Services";
		//protected override const string sNounsFolder = "Nouns";
		//#endregion

		//public UsingHierarchyTreeView(RepositoryItemBaseEx repositoryItem)
		//    : this()
		//{
		//    _repItem = repositoryItem;
		//    load();
		//}

		//public UsingHierarchyTreeView()
		//    : base()
		//{
		//    init();
		//}

		//protected override void init()
		//{
		//    ShowPlusMinus = true;
		//    ShowRootLines = true;

		//    this.MouseDown += new MouseEventHandler(UsedByHierarchyTreeView_MouseDown);

		//    #region ContextMenus

		//    System.Drawing.Bitmap img = Resources.Refresh;
		//    img.MakeTransparent(System.Drawing.Color.Magenta);

		//    #region init ContextMenu
		//    _contextMenu = new ContextMenuStrip();
		//    _contextMenu.Items.Add("Open", null, new EventHandler(OpenElement));
		//    _contextMenu.Items.Add(new ToolStripSeparator());
		//    _contextMenu.Items.Add("Expand Child Elements", Resources.tree_expandall, new EventHandler(ExpandAll));
		//    _contextMenu.Items.Add("Collapse All", Resources.tree_collapseall, new EventHandler(CollapseAll));
		//    _contextMenu.Items.Add(new ToolStripSeparator());
		//    _contextMenu.Items.Add("Refresh", img, new EventHandler(refreshView));
		//    #endregion

		//    #region init RefreshMenu
		//    _refreshMenu = new ContextMenuStrip();
		//    _refreshMenu.Items.Add("Refresh", img, new EventHandler(refreshView));
		//    #endregion

		//    #endregion

		//    #region init BackgroundWorker
		//    worker.DoWork += new DoWorkEventHandler(worker_DoWork);
		//    worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
		//    worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
		//    worker.WorkerSupportsCancellation = true;
		//    worker.WorkerReportsProgress = true;
		//    #endregion

		//    ImageList = Helpers.GetRepositoryItemTypeImageList();
		//}

		//protected override void load()
		//{
		//    if ( worker.IsBusy ) {
		//        worker.CancelAsync(BackgroundWorker worker, );
		//        while ( worker.IsBusy ) { Application.DoEvents(); }
		//    }

		//    #region reset folders
		//    _nouns = null;
		//    _businessObjects = null;
		//    _logicalMethods = null;
		//    _processes = null;
		//    _rules = null;
		//    _capabilities = null;
		//    _processesBP = null;
		//    _processesComposite = null;
		//    _processesMashup = null;
		//    _workflowInterface = null;
		//    _webservices = null;
		//    _humanActivities = null;

		//    CheckOrAddFolder(FolderType.Nouns);
		//    CheckOrAddFolder(FolderType.BusinessObjects);
		//    CheckOrAddFolder(FolderType.Capabilities);
		//    CheckOrAddFolder(FolderType.LogicalMethods);
		//    CheckOrAddFolder(FolderType.Processes);
		//    CheckOrAddFolder(FolderType.Rules);
		//    CheckOrAddFolder(FolderType.WorkflowInterface);
		//    CheckOrAddFolder(FolderType.WebServices);
		//    CheckOrAddFolder(FolderType.HumanActivities);
		//    #endregion

		//    _rootNode = createTreeNode(_repItem, false);
		//    _rootNode.Text += " (loading...)";
		//    try {
		//        worker.RunWorkerAsync(BackgroundWorker worker, );
		//    } catch ( Exception ex ) {
		//        Debug.WriteLine(ex);
		//        _rootNode.Text = RepositoryItem.Name;

		//        DialogResult result = MessageBox.Show("An error occured while loading the uses hierarchy", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
		//        if ( result == DialogResult.Retry ) {
		//            load();
		//        }
		//    }
		//}

		//#region protected override Methods
		//#region Event Handlers
		//#region BackgroundWorker
		//void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		//{
		//    _rootNode.Text = RepositoryItem.Name;
		//}

		//void worker_DoWork(object sender, DoWorkEventArgs e)
		//{
		//    if ( e.Argument == null ) {
		//        Invoke(new VoidAction(BeginUpdate));
		//        Invoke(new VoidAction(Nodes.Clear));
		//        Invoke(new VoidAction(EndUpdate));
		//        Invoke(new VoidAction(BeginUpdate));
		//        worker.ReportProgress(0, new WorkerState(Action.AddRootNode));
		//        Invoke(new VoidAction(EndUpdate));
		//        getUsedByItems(_rootNode);
		//        if ( this.IsHandleCreated ) {
		//            Invoke(new VoidAction(_rootNode.Expand));
		//        }
		//    } else if ( e.Argument is TreeNodeCollection ) {
		//        foreach ( TreeNode node in e.Argument as TreeNodeCollection ) {
		//            Invoke(new VoidAction(node.Nodes.Clear));
		//            getUsedByItems(node, true);
		//        }
		//    }
		//}

		//void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
		//{
		//    WorkerState state = e.UserState as WorkerState;
		//    switch ( state.CurrentAction ) {
		//        #region NotSpecified
		//        case Action.NotSpecified:
		//            return;
		//        #endregion
		//        #region EnqueueExpand
		//        case Action.EnqueueExpand:
		//            if ( !worker.IsBusy ) {
		//                OnBeforeExpand(new TreeViewCancelEventArgs(state.CurrentNode, false, TreeViewAction.Expand));
		//            }
		//            break;
		//        #endregion
		//        #region AddRootNode
		//        case Action.AddRootNode:
		//            Nodes.Add(_rootNode);
		//            break;
		//        #endregion
		//        #region Add/AddRange
		//        case Action.Add:
		//        case Action.AddRange:
		//            if ( state.CurrentNode == null ) throw new ArgumentNullException("CurrentNode");
		//            if ( state.NodesToAdd == null ) throw new ArgumentNullException("NodesToAdd");
		//            if ( state.CurrentNode == _processes ) {
		//                foreach ( TreeNode tn in state.NodesToAdd ) {
		//                    switch ( ( (Repository.Workflow)tn.Tag ).Type ) {
		//                        case WorkflowType.Orchestration:
		//                            if ( !_processesComposite.Nodes.ContainsKey(tn.Name) )
		//                                _processesComposite.Nodes.Add(tn);
		//                            break;
		//                        case WorkflowType.Business_Process:
		//                            if ( !_processesBP.Nodes.ContainsKey(tn.Name) )
		//                                _processesBP.Nodes.Add(tn);
		//                            break;
		//                        case WorkflowType.Mashup:
		//                        case WorkflowType.Mashup_Horizontal:
		//                            if ( !_processesMashup.Nodes.ContainsKey(tn.Name) )
		//                                _processesMashup.Nodes.Add(tn);
		//                            break;
		//                        default:
		//                            break;
		//                    }
		//                }
		//            } else {
		//                foreach ( TreeNode tn in state.NodesToAdd ) {
		//                    if ( !state.CurrentNode.Nodes.ContainsKey(tn.Name) &&
		//                         !itemExistsRecursive(state.CurrentNode, tn) ) {
		//                        state.CurrentNode.Nodes.Add(tn);
		//                    }
		//                }
		//            }
		//            break;
		//        #endregion
		//        default:
		//            break;
		//    }
		//    if ( state.CurrentAction == Action.Add || state.CurrentAction == Action.AddRange ) {
		//        CheckOrAddFolder(FolderType.Nouns);
		//        CheckOrAddFolder(FolderType.BusinessObjects);
		//        CheckOrAddFolder(FolderType.Capabilities);
		//        CheckOrAddFolder(FolderType.LogicalMethods);
		//        CheckOrAddFolder(FolderType.Processes);
		//        CheckOrAddFolder(FolderType.Rules);
		//        CheckOrAddFolder(FolderType.WorkflowInterface);
		//        CheckOrAddFolder(FolderType.WebServices);
		//        CheckOrAddFolder(FolderType.HumanActivities);
		//    }
		//}

		//#endregion

		//#region ContextMenu
		//void OpenElement(object sender, EventArgs e)
		//{
		//    IMainController mc = _repItem.GetService(typeof(IMainController)) as IMainController;
		//    if ( mc != null ) {
		//        TreeNode node = this.SelectedNode;
		//        RepositoryItemBase item = node.Tag as RepositoryItemBase;
		//        if ( item != null ) {
		//            RepositoryBusinessRule rule = item as RepositoryBusinessRule;
		//            if ( rule != null ) {
		//                BusinessPolicy policy = rule.GetPolicy();
		//                mc.OpenDiagram(policy);
		//            } else {
		//                mc.OpenDiagram(item);
		//            }
		//        }
		//    }
		//}

		//void ExpandAll(object sender, EventArgs e)
		//{
		//    this.BeginUpdate();
		//    SelectedNode.Expand();
		//    this.EndUpdate();
		//    this.BeginUpdate();
		//    foreach ( TreeNode node in SelectedNode.Nodes ) {
		//        node.Expand();
		//    }
		//    this.EndUpdate();
		//    //SelectedNode.ExpandAll();
		//}

		//void CollapseAll(object sender, EventArgs e)
		//{
		//    this.BeginUpdate();
		//    SelectedNode.Collapse(false);
		//    this.EndUpdate();
		//}

		//void refreshView(object sender, EventArgs e)
		//{
		//    load();
		//}

		//void UsedByHierarchyTreeView_MouseDown(object sender, MouseEventArgs e)
		//{
		//    if ( e.Button == MouseButtons.Right ) {
		//        SelectedNode = GetNodeAt(e.Location);
		//        if ( SelectedNode != null ) {
		//            RepositoryItemBase item = SelectedNode.Tag as RepositoryItemBase;
		//            _contextMenu.Items[0].Enabled = true;
		//            _contextMenu.Items[2].Enabled = true;
		//            _contextMenu.Items[3].Enabled = true;
		//            if ( item != null ) {
		//                switch ( item.RepositoryItemType ) {
		//                    case ItemType.LogicalWebMethod:
		//                    case ItemType.Noun:
		//                    case ItemType.GenericFolder:
		//                    case ItemType.Verb:
		//                    case ItemType.WebMethod:
		//                    case ItemType.WebService:
		//                    case ItemType.Workflow_Method:
		//                    case ItemType.Workflow_Field:
		//                    case ItemType.Workflow_Event:
		//                        _contextMenu.Items[0].Enabled = false;
		//                        break;
		//                    default:
		//                        break;
		//                }
		//            } else {
		//                _contextMenu.Items[0].Enabled = false;
		//            }
		//        } else {
		//            _refreshMenu.Show(this, e.Location);
		//        }
		//    }
		//}

		//#endregion
		//#endregion

		#region getItemsOfRepositoryItem
		// Schema
		// getItemsOfType(Type item, bool deeper){
		//	get SearchableSortableBindingList of items using parameter item
		//	--- or ---
		//	get items of the parameter items properties
		//	add the items to the return value (using createTreeNode() / createTreeNodeArray(worker, ))
		// }

		protected override TreeNode[] getItemsOfNoun(BackgroundWorker worker, Noun item, bool deeper)
		{
			#region old
			//SearchableSortableBindingList<BusinessObject> bobjects = Global.Data.GetBusinessObjectsOfNoun(item.ID);

			List<TreeNode> list = new List<TreeNode>();
			//foreach ( BusinessObject bo in bobjects ) {
			//    list.Add(createTreeNode(worker, bo, deeper));
			//}
			return list.ToArray();
			#endregion
		}

		protected override TreeNode[] getItemsOfBusinessObject(BackgroundWorker worker, BusinessObject item, bool deeper)
		{
			BindingListEx<Noun> nouns = new BindingListEx<Noun>();
			BindingListEx<BusinessObject> bobjects = new BindingListEx<BusinessObject>();
			foreach ( BusinessObjectField bof in item.BusinessObjectFields ) {
				if ( bof.NounID > 0 ) {
					nouns.Add(bof.Noun);
				} else if ( bof.BusinessObjectID > 0 ) {
					bobjects.Add(bof.BusinessObject);
				}
			}

			List<TreeNode> nodes = new List<TreeNode>();

			nodes.AddRange(createTreeNodeArray(worker, nouns, deeper));
			nodes.AddRange(createTreeNodeArray(worker, bobjects, deeper));

			return nodes.ToArray();
		}

		protected override TreeNode[] getItemsOfVerb(BackgroundWorker worker, Verb item, bool deeper)
		{
			List<TreeNode> nodes = new List<TreeNode>();

			BindingListEx<BusinessObject> bobjects = new BindingListEx<BusinessObject>();
			if ( item.InputBusinessObject != null ) {
				bobjects.Add(item.InputBusinessObject);
			}
			if ( item.OutputBusinessObject != null ) {
				bobjects.Add(item.OutputBusinessObject);
			}
			nodes.AddRange(createTreeNodeArray(worker, bobjects, deeper));

			//CheckOrAddFolder(FolderType.LogicalMethods);
			BindingListEx<LogicalWebMethod> lwms = Global.Data.GetLogicalMethodsOfVerb(item.ID);
			nodes.AddRange(createTreeNodeArray(worker, lwms, deeper));

			return nodes.ToArray();
		}

		protected override TreeNode[] getItemsOfBusinessRule(BackgroundWorker worker, RepositoryBusinessRule item, bool deeper)
		{
			List<TreeNode> nodes = new List<TreeNode>();
			Noun n = null;
			RuleConstant rc = null;
			RepositoryBusinessRule brule = null;
			foreach ( var condition in item.ExtendedProperties.Conditions ) {
				if ( condition.LeftNounID > 0 ) {
					n = Global.Data.RepositoryService.GetItem<Noun>(condition.LeftNounID);
					if ( n != null ) nodes.Add(createTreeNode(worker, n, deeper));
				} else if ( condition.LeftRuleConstID > 0 ) {
					rc = Global.Data.RepositoryService.GetItem<RuleConstant>(condition.LeftRuleConstID);
					if ( rc != null ) nodes.Add(createTreeNode(worker, rc, deeper));
				} else if ( condition.LeftRuleID > 0 ) {
					brule = Global.Data.RepositoryService.GetItem<RepositoryBusinessRule>(condition.LeftRuleID);
					if ( brule != null ) nodes.Add(createTreeNode(worker, brule, deeper));
				}
				if ( condition.RightNounID > 0 ) {
					n = Global.Data.RepositoryService.GetItem<Noun>(condition.RightNounID);
					if ( n != null ) nodes.Add(createTreeNode(worker, n, deeper));
				} else if ( condition.RightRuleConstID > 0 ) {
					rc = Global.Data.RepositoryService.GetItem<RuleConstant>(condition.RightRuleConstID);
					if ( rc != null ) nodes.Add(createTreeNode(worker, rc, deeper));
				} else if ( condition.RightRuleID > 0 ) {
					brule = Global.Data.RepositoryService.GetItem<RepositoryBusinessRule>(condition.RightRuleID);
					if ( brule != null ) nodes.Add(createTreeNode(worker, brule, deeper));
				}
			}
			return nodes.ToArray();
		}

		protected override TreeNode[] getItemsOfLogicalMethod(BackgroundWorker worker, LogicalWebMethod item, bool deeper)
		{
			List<TreeNode> nodes = new List<TreeNode>();
			if ( item.WebService != null ) {
				nodes.Add(createTreeNode(worker, item.WebService, deeper));
			} else if ( item.HumanActivity != null ) {
				nodes.Add(createTreeNode(worker, item.HumanActivity, deeper));
			}
			if ( item.InputBusinessObject != null ) {
				nodes.Add(createTreeNode(worker, item.InputBusinessObject, deeper));
			}
			if ( item.OutputBusinessObject != null ) {
				nodes.Add(createTreeNode(worker, item.OutputBusinessObject, deeper));
			}
			if ( item.EndpointRule != null ) {
				nodes.Add(createTreeNode(worker, item.EndpointRule, deeper));
			}

			return nodes.ToArray();
		}

		protected override TreeNode[] getItemsOfWebMethod(BackgroundWorker worker, WebMethod item, bool deeper)
		{
			#region old
			//SearchableSortableBindingList<Verb> verbs = Global.Data.GetVerbsOfWebMethod(item.ID);

			List<TreeNode> nodes = new List<TreeNode>();
			//if ( item.WebService != null ) {
			//    nodes.Add(createTreeNode(worker, item.WebService, deeper));
			//}
			//nodes.AddRange(createTreeNodeArray(worker, verbs, deeper));

			return nodes.ToArray();

			#endregion
		}

		protected override TreeNode[] getItemsOfWebService(BackgroundWorker worker, WebService item, bool deeper)
		{

			BindingListEx<WebMethod> methods = item.GetWebMethods();
			List<TreeNode> nodes = new List<TreeNode>();
			nodes.AddRange(createTreeNodeArray(worker, methods, deeper));

			return nodes.ToArray();
		}

		protected override TreeNode[] getItemsOfHumanActivity(BackgroundWorker worker, Repository.HumanActivity item, bool deeper)
		{
			#region old
			//SearchableSortableBindingList<LogicalWebMethod> lwms = Global.Data.GetLogicalWebMethodsOfHumanActivity(item.ID);

			List<TreeNode> nodes = new List<TreeNode>();
			//nodes.AddRange(createTreeNodeArray(worker, lwms, deeper));

			return nodes.ToArray();
			#endregion
		}

		protected override TreeNode[] getItemsOfRuleConstants(BackgroundWorker worker, RuleConstant item, bool deeper)
		{
			#region old
			//SearchableSortableBindingList<RepositoryBusinessRule> rules = Global.Data.GetBusinessRulesOfRuleConstant(item.ID);

			List<TreeNode> nodes = new List<TreeNode>();
			//nodes.AddRange(createTreeNodeArray(worker, rules, deeper));

			return nodes.ToArray();
			#endregion
		}

		protected override TreeNode[] getItemsOfCapability(BackgroundWorker worker, ServiceModule item, bool deeper)
		{
			#region old
			//SearchableSortableBindingList<Verb> verbs = item.GetVerbs();
			List<TreeNode> nodes = new List<TreeNode>();
			//foreach ( Verb verb in verbs ) {
			//    SearchableSortableBindingList<Repository.Workflow> workflows = Global.Data.GetWorkflowsOfVerb(verb.ID);
			//    nodes.AddRange(createTreeNodeArray(worker, workflows, deeper));
			//}
			return nodes.ToArray();
			#endregion
		}

		protected override TreeNode[] getItemsOfWorkflow(BackgroundWorker worker, Repository.Workflow item, bool deeper)
		{
			List<TreeNode> nodes = new List<TreeNode>();

			BindingListEx<Verb> verbs = new BindingListEx<Verb>();
			if ( item.Capability != null ) {
				verbs.Add(item.Capability);
			}

			BindingListEx<LogicalActivity> logActs = Global.Data.GetLogicalActivitiesOfWorkflow(item.ID);
			BindingListEx<RepositoryBusinessRule> rules = item.GetRules();
			BindingListEx<Repository.HumanActivity> humanActs = new BindingListEx<OpenComposite.EII.Repository.HumanActivity>();
			BindingListEx<WebService> webservices = new BindingListEx<WebService>();
			foreach ( LogicalActivity logAct in logActs ) {
				Verb v = logAct.Verb;
				if ( v != null ) verbs.Add(v);
				RepositoryBusinessRule r = logAct.GetBusinessRule();
				if ( r != null ) rules.Add(r);
				Repository.HumanActivity ha = logAct.GetHumanActivity();
				if ( ha != null ) humanActs.Add(ha);
				WebService ws = logAct.GetWebService();
				if ( ws != null ) webservices.Add(ws);
			}

			nodes.AddRange(createTreeNodeArray(worker, verbs, deeper));
			nodes.AddRange(createTreeNodeArray(worker, rules, deeper));
			nodes.AddRange(createTreeNodeArray(worker, humanActs, deeper));
			nodes.AddRange(createTreeNodeArray(worker, webservices, deeper));

			BindingListEx<WorkflowEvent> events = Global.Data.GetWorkflowEvents(item.ID);
			nodes.AddRange(createTreeNodeArray(worker, events, deeper));

			BindingListEx<WorkflowMethod> methods = Global.Data.GetWorkflowMethods(item.ID);
			nodes.AddRange(createTreeNodeArray(worker, methods, deeper));

			BindingListEx<WorkflowField> fields = Global.Data.GetWorkflowFields(item.ID);
			nodes.AddRange(createTreeNodeArray(worker, fields, deeper));

			return nodes.ToArray();
		}

		private TreeNode[] getItemsOfWorkflowField(BackgroundWorker worker, WorkflowField item, bool deeper)
		{
			List<TreeNode> nodes = new List<TreeNode>();
			if ( item.BusinessObjectID > 0 ) {
				nodes.Add(createTreeNode(worker, item.BusinessObject, deeper));
			}
			return nodes.ToArray();
		}

		private TreeNode[] getItemsOfWorkflowEvent(BackgroundWorker worker, WorkflowEvent item, bool deeper)
		{
			List<TreeNode> nodes = new List<TreeNode>();
			if ( item.BusinessObjectID > 0 ) {
				nodes.Add(createTreeNode(worker, item.BusinessObject, deeper));
			}
			return nodes.ToArray();
		}

		private TreeNode[] getItemsOfWorkflowMethod(BackgroundWorker worker, WorkflowMethod item, bool deeper)
		{
			List<TreeNode> nodes = new List<TreeNode>();
			if ( item.InputBusinessObjectID > 0 ) {
				nodes.Add(createTreeNode(worker, item.InputBusinessObject, deeper));
			}
			if ( item.OutputBusinessObjectID > 0 ) {
				nodes.Add(createTreeNode(worker, item.OutputBusinessObject, deeper));
			}
			return nodes.ToArray();
		}
		#endregion

		#region [Async] getItemsOfRepositoryItem
		// Schema
		// getItemsOfTypeAsync(BackgroundWorker worker, Type item){
		//	--- do this for each Type using the parameter item ---
		//	CheckOrAddFolder(FolderType)
		//	create SearchableSortableBindingList of Items using parameter item
		//	--- or ---
		//	get items of the parameter items properties
		//	report progress to worker, 
		//		use Action.Add or Action.AddRange, 
		//		use the correct folder node (see enum FolderType for further information), 
		//		use createTreeNode() / createTreeNodeArray(worker, ) on the SearchableSortableBindingList
		//	--- optionally get items using using items (e.g. get items using BusinessObjects which are using a Noun) ---
		//	--- !!!use this with caution of endless loops!!! ---
		//	use getItemsOfTypeAsync(BackgroundWorker worker, ) for each item in the SearchableSortableBindingList
		// }

		protected override void getItemsOfNounAsync(BackgroundWorker worker, Noun item)
		{
			if ( worker.CancellationPending ) return;
		}

		protected override void getItemsOfBusinessObjectAsync(BackgroundWorker worker, BusinessObject item)
		{
			bool deeper = true;

			BindingListEx<Noun> nouns = new BindingListEx<Noun>();
			BindingListEx<BusinessObject> bobjects = new BindingListEx<BusinessObject>();
			foreach ( BusinessObjectField bof in item.BusinessObjectFields ) {
				if ( bof.NounID > 0 ) {
					nouns.Add(bof.Noun);
				} else if ( bof.BusinessObjectID > 0 ) {
					bobjects.Add(bof.BusinessObject);
				}
			}

			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _nouns, createTreeNodeArray(worker, nouns, deeper)));
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _businessObjects, createTreeNodeArray(worker, bobjects, deeper)));
			foreach ( BusinessObject bo in bobjects ) {
				getItemsOfBusinessObjectAsync(worker, bo);
			}
			#region old
			//CheckOrAddFolder(FolderType.BusinessObjects);
			//SearchableSortableBindingList<BusinessObject> parentBOs = Global.Data.GetParentBusinessObjects(item.ID);
			//worker.ReportProgress(0, new WorkerState(Action.AddRange, _businessObjects, createTreeNodeArray(worker, parentBOs, deeper)));

			//CheckOrAddFolder(FolderType.Capabilities);
			//SearchableSortableBindingList<Verb> verbs = Global.Data.GetVerbsOfBusinessObject(item.ID);
			//worker.ReportProgress(0, new WorkerState(Action.AddRange, _capabilities, createTreeNodeArray(worker, verbs, deeper)));

			//CheckOrAddFolder(FolderType.Processes);
			//SearchableSortableBindingList<Repository.Workflow> workflows = Global.Data.GetWorkflowsOfBusinessObject(item.ID);
			//worker.ReportProgress(0, new WorkerState(Action.AddRange, _processes, createTreeNodeArray(worker, workflows, deeper)));

			//CheckOrAddFolder(FolderType.LogicalMethods);
			//SearchableSortableBindingList<LogicalWebMethod> logMeths = Global.Data.GetLogicalMethodsOfBusinessObject(item.ID);
			//worker.ReportProgress(0, new WorkerState(Action.AddRange, _logicalMethods, createTreeNodeArray(worker, logMeths, deeper)));

			//CheckOrAddFolder(FolderType.WorkflowInterface);
			//SearchableSortableBindingList<WorkflowMethod> wfM = Global.Data.GetWorkflowMethodOfBusinessObject(item.ID);
			//worker.ReportProgress(0, new WorkerState(Action.AddRange, _workflowInterface, createTreeNodeArray(worker, wfM, deeper)));

			//SearchableSortableBindingList<WorkflowField> wfF = Global.Data.GetWorkflowFieldOfBusinessObject(item.ID);
			//worker.ReportProgress(0, new WorkerState(Action.AddRange, _workflowInterface, createTreeNodeArray(worker, wfF, deeper)));

			//SearchableSortableBindingList<WorkflowEvent> wfE = Global.Data.GetWorkflowEventOfBusinessObject(item.ID);
			//worker.ReportProgress(0, new WorkerState(Action.AddRange, _workflowInterface, createTreeNodeArray(worker, wfE, deeper)));

			//foreach ( Verb verb in verbs ) {
			//    getItemsOfVerbAsync(BackgroundWorker worker, verb);
			//}

			//foreach ( BusinessObject bo in parentBOs ) {
			//    getItemsOfBusinessObjectAsync(BackgroundWorker worker, bo);
			//}

			//SearchableSortableBindingList<Repository.Workflow> wfs = new SearchableSortableBindingList<OpenComposite.EII.Repository.Workflow>();
			//foreach ( WorkflowMethod wm in wfM ) {
			//    wfs.Add(wm.Workflow);
			//}
			//foreach ( WorkflowField wf in wfF ) {
			//    wfs.Add(wf.Workflow);
			//}
			//foreach ( WorkflowEvent we in wfE ) {
			//    wfs.Add(we.Workflow);
			//}
			//worker.ReportProgress(0, new WorkerState(Action.AddRange, _processes, createTreeNodeArray(worker, wfs, deeper)));
			#endregion
		}

		protected override void getItemsOfVerbAsync(BackgroundWorker worker, Verb item)
		{
			bool deeper = true;

			BindingListEx<BusinessObject> bobjects = new BindingListEx<BusinessObject>();
			if ( item.InputBusinessObject != null ) {
				bobjects.Add(item.InputBusinessObject);
			}
			if ( item.OutputBusinessObject != null ) {
				bobjects.Add(item.OutputBusinessObject);
			}
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _businessObjects, createTreeNodeArray(worker, bobjects, deeper)));

			//CheckOrAddFolder(FolderType.LogicalMethods);
			BindingListEx<LogicalWebMethod> lwms = Global.Data.GetLogicalMethodsOfVerb(item.ID);
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _logicalMethods, createTreeNodeArray(worker, lwms, deeper)));

			foreach ( BusinessObject bo in bobjects ) {
				getItemsOfBusinessObjectAsync(worker, bo);
			}

			foreach ( LogicalWebMethod lwm in lwms ) {
				getItemsOfLogicalMethodAsync(worker, lwm);
			}

			#region old
			//CheckOrAddFolder(FolderType.Processes);
			//SearchableSortableBindingList<Repository.Workflow> workflows = Global.Data.GetWorkflowsOfVerb(item.ID);
			//worker.ReportProgress(0, new WorkerState(Action.AddRange, _processes, createTreeNodeArray(worker, workflows, deeper)));

			//CheckOrAddFolder(FolderType.LogicalMethods);
			//SearchableSortableBindingList<LogicalWebMethod> lwms = Global.Data.GetLogicalMethodsOfVerb(item.ID);
			//worker.ReportProgress(0, new WorkerState(Action.AddRange, _logicalMethods, createTreeNodeArray(worker, lwms, deeper)));
			#endregion
		}

		protected override void getItemsOfBusinessRuleAsync(BackgroundWorker worker, RepositoryBusinessRule item)
		{
			bool deeper = true;

			BindingListEx<Noun> nouns = new BindingListEx<Noun>();
			BindingListEx<RepositoryBusinessRule> brules = new BindingListEx<RepositoryBusinessRule>();
			BindingListEx<RuleConstant> constants = new BindingListEx<RuleConstant>();
			foreach ( var condition in item.ExtendedProperties.Conditions ) {
				if ( condition.LeftNounID > 0 ) {
					nouns.Add(Global.Data.RepositoryService.GetItem<Noun>(condition.LeftNounID));
				} else if ( condition.LeftRuleConstID > 0 ) {
					constants.Add(Global.Data.RepositoryService.GetItem<RuleConstant>(condition.LeftRuleConstID));
				} else if ( condition.LeftRuleID > 0 ) {
					brules.Add(Global.Data.RepositoryService.GetItem<RepositoryBusinessRule>(condition.LeftRuleID));
				}
				if ( condition.RightNounID > 0 ) {
					nouns.Add(Global.Data.RepositoryService.GetItem<Noun>(condition.RightNounID));
				} else if ( condition.RightRuleConstID > 0 ) {
					constants.Add(Global.Data.RepositoryService.GetItem<RuleConstant>(condition.RightRuleConstID));
				} else if ( condition.RightRuleID > 0 ) {
					brules.Add(Global.Data.RepositoryService.GetItem<RepositoryBusinessRule>(condition.RightRuleID));
				}
			}

			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _nouns, createTreeNodeArray(worker, nouns, deeper)));
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _rules, createTreeNodeArray(worker, brules, deeper)));
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _ruleConstants, createTreeNodeArray(worker, constants, deeper)));
		}

		protected override void getItemsOfLogicalMethodAsync(BackgroundWorker worker, LogicalWebMethod item)
		{
			bool deeper = true;

			BindingListEx<BusinessObject> bobjects = new BindingListEx<BusinessObject>();
			if ( item.InputBusinessObject != null ) {
				bobjects.Add(item.InputBusinessObject);
				getItemsOfBusinessObjectAsync(worker, item.InputBusinessObject);
			}
			if ( item.OutputBusinessObject != null ) {
				bobjects.Add(item.OutputBusinessObject);
				getItemsOfBusinessObjectAsync(worker, item.OutputBusinessObject);
			}
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _businessObjects, createTreeNodeArray(worker, bobjects, deeper)));


			if ( item.WebService != null ) {
				//CheckOrAddFolder(FolderType.WebServices);
				worker.ReportProgress(0, new WorkerState(TraverseAction.Add, _webservices, createTreeNode(worker, item.WebService, deeper)));
				getItemsOfWebServiceAsync(worker, item.WebService);
			} else if ( item.HumanActivity != null ) {
				//CheckOrAddFolder(FolderType.HumanActivities);
				worker.ReportProgress(0, new WorkerState(TraverseAction.Add, _humanActivities, createTreeNode(worker, item.HumanActivity, deeper)));
			}

			if ( item.EndpointRule != null ) {
				worker.ReportProgress(0, new WorkerState(TraverseAction.Add, _rules, createTreeNode(worker, item.EndpointRule, deeper)));
				getItemsOfBusinessRuleAsync(worker, item.EndpointRule);
				BindingListEx<LogicalRuleResultEndpoint> endpoints = item.GetLogicalRuleResultEndpoints();
				foreach ( LogicalRuleResultEndpoint ep in endpoints ) {
					if ( ep.CallbackWebMethod != null ) {
						worker.ReportProgress(0, new WorkerState(TraverseAction.Add, _webservices, createTreeNode(worker, ep.CallbackWebMethod.WebService, deeper)));
						getItemsOfWebServiceAsync(worker, ep.CallbackWebMethod.WebService);
					}
					if ( ep.HumanActivity != null ) {
						worker.ReportProgress(0, new WorkerState(TraverseAction.Add, _humanActivities, createTreeNode(worker, ep.HumanActivity, deeper)));
						getItemsOfHumanActivityAsync(worker, ep.HumanActivity);
					}
					if ( ep.ProxyCallbackWebMethod != null ) {
						worker.ReportProgress(0, new WorkerState(TraverseAction.Add, _webservices, createTreeNode(worker, ep.ProxyCallbackWebMethod.WebService, deeper)));
						getItemsOfWebServiceAsync(worker, ep.ProxyCallbackWebMethod.WebService);
					}
					if ( ep.ProxyWebMethod != null ) {
						worker.ReportProgress(0, new WorkerState(TraverseAction.Add, _webservices, createTreeNode(worker, ep.ProxyWebMethod.WebService, deeper)));
						getItemsOfWebServiceAsync(worker, ep.ProxyWebMethod.WebService);
					}
					if ( ep.WebMethod != null ) {
						worker.ReportProgress(0, new WorkerState(TraverseAction.Add, _webservices, createTreeNode(worker, ep.WebMethod.WebService, deeper)));
						getItemsOfWebServiceAsync(worker, ep.WebMethod.WebService);
					}
				}
			}
		}

		protected override void getItemsOfWebMethodAsync(BackgroundWorker worker, WebMethod item)
		{
			bool deeper = true;

			BindingListEx<LogicalWebMethod> lwms = Global.Data.GetLogicalWebMethodsOfWebMethod(item.ID);
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _logicalMethods, createTreeNodeArray(worker, lwms, deeper)));

			foreach ( LogicalWebMethod method in lwms ) {
				getItemsOfLogicalMethodAsync(worker, method);
			}

			if ( item.WebService != null ) {
				worker.ReportProgress(0, new WorkerState(TraverseAction.Add, _webservices, createTreeNode(worker, item.WebService, deeper)));
			}
		}

		protected override void getItemsOfWebServiceAsync(BackgroundWorker worker, WebService item)
		{
			//bool deeper = true;

			//SearchableSortableBindingList<WebMethod> methods = item.GetWebMethods();
		}

		protected override void getItemsOfHumanActivityAsync(BackgroundWorker worker, Repository.HumanActivity item)
		{
			bool deeper = true;

			#region old
			//CheckOrAddFolder(FolderType.LogicalMethods);
			BindingListEx<LogicalWebMethod> lwms = Global.Data.GetLogicalWebMethodsOfHumanActivity(item.ID);
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _logicalMethods, createTreeNodeArray(worker, lwms, deeper)));
			#endregion
		}

		protected override void getItemsOfRuleConstantsAsync(BackgroundWorker worker, RuleConstant item)
		{
			bool deeper = true;

			#region old
			//CheckOrAddFolder(FolderType.Rules);
			BindingListEx<RepositoryBusinessRule> rules = Global.Data.GetBusinessRulesOfRuleConstant(item.ID);
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _rules, createTreeNodeArray(worker, rules, deeper)));
			#endregion
		}

		protected override void getItemsOfCapabilityAsync(BackgroundWorker worker, ServiceModule item)
		{
			bool deeper = true;

			BindingListEx<Verb> verbs = item.GetVerbs();

			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _capabilities, createTreeNodeArray(worker, verbs, deeper)));

			foreach ( Verb verb in verbs ) {
				getItemsOfVerbAsync(worker, verb);
			}

			BindingListEx<Repository.Workflow> workflows = new BindingListEx<Repository.Workflow>();
			foreach ( Verb verb in verbs ) {
				workflows.AddRange(Global.Data.GetWorkflowsOfVerb(verb.ID));
			}
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _processes, createTreeNodeArray(worker, workflows, deeper)));


		}

		protected override void getItemsOfWorkflowAsync(BackgroundWorker worker, Repository.Workflow item)
		{
			bool deeper = true;

			BindingListEx<Verb> verbs = new BindingListEx<Verb>();
			if ( item.Capability != null ) {
				verbs.Add(item.Capability);
			}

			BindingListEx<LogicalActivity> logActs = Global.Data.GetLogicalActivitiesOfWorkflow(item.ID);
			BindingListEx<RepositoryBusinessRule> rules = item.GetRules();
			BindingListEx<Repository.HumanActivity> humanActs = new BindingListEx<OpenComposite.EII.Repository.HumanActivity>();
			BindingListEx<WebService> webservices = new BindingListEx<WebService>();
			foreach ( LogicalActivity logAct in logActs ) {
				Verb v = logAct.Verb;
				if ( v != null ) verbs.Add(v);
				RepositoryBusinessRule r = logAct.GetBusinessRule();
				if ( r != null ) rules.Add(r);
				Repository.HumanActivity ha = logAct.GetHumanActivity();
				if ( ha != null ) humanActs.Add(ha);
				WebService ws = logAct.GetWebService();
				if ( ws != null ) webservices.Add(ws);
			}
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _capabilities, createTreeNodeArray(worker, verbs, deeper)));

			foreach ( Verb verb in verbs ) {
				getItemsOfVerbAsync(worker, verb);
			}

			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _rules, createTreeNodeArray(worker, rules, deeper)));

			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _webservices, createTreeNodeArray(worker, webservices, true)));

			foreach ( WebService ws in webservices ) {
				getItemsOfWebServiceAsync(worker, ws);
			}

			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _humanActivities, createTreeNodeArray(worker, humanActs, deeper)));

			BindingListEx<WorkflowEvent> events = Global.Data.GetWorkflowEvents(item.ID);
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _workflowInterface, createTreeNodeArray(worker, events, deeper)));

			BindingListEx<WorkflowMethod> methods = Global.Data.GetWorkflowMethods(item.ID);
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _workflowInterface, createTreeNodeArray(worker, methods, deeper)));

			BindingListEx<WorkflowField> fields = Global.Data.GetWorkflowFields(item.ID);
			worker.ReportProgress(0, new WorkerState(TraverseAction.AddRange, _workflowInterface, createTreeNodeArray(worker, fields, deeper)));
		}
		#endregion

		//protected override bool itemExistsRecursive(TreeNode parent, TreeNode nodeToCheck)
		//{
		//    bool flag = parent.Nodes.ContainsKey(nodeToCheck.Name);
		//    if ( flag ) return true;

		//    if ( parent.Parent != null ) {
		//        flag = itemExistsRecursive(parent.Parent, nodeToCheck);
		//    }
		//    return flag;
		//}

		//#region TreeNode creators
		///// <summary>
		///// Creates an Array of TreeNodes based on a SearchableSortableBindingList of RepositoryItemBase
		///// </summary>
		///// <typeparam name="T"></typeparam>
		///// <param name="items"></param>
		///// <param name="deeper"></param>
		///// <returns></returns>
		//protected override TreeNode[] createTreeNodeArray<T>(SearchableSortableBindingList<T> items, bool deeper) where T : RepositoryItemBase
		//{
		//    List<TreeNode> list = new List<TreeNode>();
		//    foreach ( RepositoryItemBase item in items ) {
		//        if ( items != null ) {
		//            list.Add(createTreeNode(worker, item, deeper));
		//        }
		//    }
		//    return list.ToArray();
		//}

		///// <summary>
		///// Creates a TreeNode based on a RepositoryItemBase
		///// </summary>
		///// <param name="item"></param>
		///// <param name="deeper"></param>
		///// <returns></returns>
		//protected override TreeNode createTreeNode(RepositoryItemBase item, bool deeper)
		//{
		//    string name = string.Format("{0}.{1}", item.Name, item.ID);
		//    string text;
		//    if ( item is RepositoryBusinessRule ) {
		//        text = string.Format("{0} ({1})", item.Name, item.NText);
		//    } else if ( item is RuleConstant ) {
		//        text = string.Format("{0} ({1})", item.Name, ( item as RuleConstant ).Value);
		//    }else {
		//        text = item.Name;
		//    }
		//    TreeNode tn = new TreeNode(text);
		//    tn.Name = name;
		//    tn.Tag = item;
		//    tn.SelectedImageKey = item.ImageKey;
		//    tn.StateImageKey = item.ImageKey;
		//    tn.ImageKey = item.ImageKey;
		//    tn.ContextMenuStrip = _contextMenu;
		//    if ( deeper ) getUsedByItems(tn, false);
		//    //if ( item is BusinessObject && !_bobjList.Contains(item.ID) ) {
		//    //    _bobjList.Add(item.ID);
		//    //}

		//    return tn;
		//}

		///// <summary>
		///// Create a folder with specified name ang image key
		///// </summary>
		///// <param name="name"></param>
		///// <param name="imageKey"></param>
		///// <returns></returns>
		//protected override TreeNode createFolderTreeNode(string name, string imageKey)
		//{
		//    TreeNode tn = new TreeNode(name);
		//    tn.Name = name;
		//    tn.ImageKey = imageKey;
		//    tn.SelectedImageKey = imageKey;
		//    tn.ContextMenuStrip = _contextMenu;
		//    return tn;
		//}
		//#endregion

		//protected override void CheckOrAddFolder(FolderType type)
		//{
		//    switch ( type ) {
		//        case FolderType.Capabilities:
		//            #region Capabilities
		//            if ( _capabilities == null ) {
		//                _capabilities = createFolderTreeNode(sCapabilitiesFolder,
		//                    "folder_closed_method");
		//            } else {
		//                if ( _capabilities.Nodes.Count > 0 && !_rootNode.Nodes.Contains(_capabilities) ) {
		//                    if ( worker != null ) {
		//                        worker.ReportProgress(0, new WorkerState(Action.Add, _rootNode, _capabilities));
		//                    } else {
		//                        _rootNode.Nodes.Add(_capabilities);
		//                    }
		//                }
		//            }
		//            break;
		//            #endregion
		//        case FolderType.Processes:
		//            #region Processes
		//            if ( _processes == null ) {
		//                _processes = new TreeNode(sProcessesFolder);
		//                _processesBP = createFolderTreeNode(sProcessesBPFolder,
		//                    "folder_closed_bprocess");
		//                _processesComposite = createFolderTreeNode(sProcessesCompositeFolder,
		//                    "folder_closed_workflows");
		//                _processesMashup = createFolderTreeNode(sProcessesMashupFolder,
		//                    "folder_closed_mashup");
		//            } else {
		//                if ( _processesBP.Nodes.Count > 0 && !_rootNode.Nodes.Contains(_processesBP) ) {
		//                    if ( worker != null ) {
		//                        worker.ReportProgress(0, new WorkerState(Action.Add, _rootNode, _processesBP));
		//                    } else {
		//                        _rootNode.Nodes.Add(_processesBP);
		//                    }
		//                }
		//                if ( _processesComposite.Nodes.Count > 0 && !_rootNode.Nodes.Contains(_processesComposite) ) {
		//                    if ( worker != null ) {
		//                        worker.ReportProgress(0, new WorkerState(Action.Add, _rootNode, _processesComposite));
		//                    } else {
		//                        _rootNode.Nodes.Add(_processesComposite);
		//                    }
		//                }
		//                if ( _processesMashup.Nodes.Count > 0 && !_rootNode.Nodes.Contains(_processesMashup) ) {
		//                    if ( worker != null ) {
		//                        worker.ReportProgress(0, new WorkerState(Action.Add, _rootNode, _processesMashup));
		//                    } else {
		//                        _rootNode.Nodes.Add(_processesMashup);
		//                    }
		//                }
		//            }
		//            break;
		//            #endregion
		//        case FolderType.BusinessObjects:
		//            #region Business Objects
		//            if ( _businessObjects == null ) {
		//                _businessObjects = createFolderTreeNode(sBusinessObjectFolder,
		//                    "bobj_folder_closed");
		//            } else {
		//                if ( _businessObjects.Nodes.Count > 0 && !_rootNode.Nodes.Contains(_businessObjects) ) {
		//                    if ( worker != null ) {
		//                        worker.ReportProgress(0, new WorkerState(Action.Add, _rootNode, _businessObjects));
		//                    } else {
		//                        _rootNode.Nodes.Add(_businessObjects);
		//                    }
		//                }
		//            }
		//            break;
		//            #endregion
		//        case FolderType.Rules:
		//            #region Rules
		//            if ( _rules == null ) {
		//                _rules = createFolderTreeNode(sRulesFolder,
		//                    "policy_folder_closed");
		//            } else {
		//                if ( _rules.Nodes.Count > 0 && !_rootNode.Nodes.Contains(_rules) ) {
		//                    if ( worker != null ) {
		//                        worker.ReportProgress(0, new WorkerState(Action.Add, _rootNode, _rules));
		//                    } else {
		//                        _rootNode.Nodes.Add(_rules);
		//                    }
		//                }
		//            }
		//            break;
		//            #endregion
		//        case FolderType.LogicalMethods:
		//            #region Logical Web Methods
		//            if ( _logicalMethods == null ) {
		//                _logicalMethods = createFolderTreeNode(sLogicalMethodsFolder,
		//                    "folder_closed_logmethod");
		//            } else {
		//                if ( _logicalMethods.Nodes.Count > 0 && !_rootNode.Nodes.Contains(_logicalMethods) ) {
		//                    if ( worker != null ) {
		//                        worker.ReportProgress(0, new WorkerState(Action.Add, _rootNode, _logicalMethods));
		//                    } else {
		//                        _rootNode.Nodes.Add(_logicalMethods);
		//                    }
		//                }
		//            }
		//            break;
		//            #endregion
		//        case FolderType.WorkflowInterface:
		//            #region Workflow Interface
		//            if ( _workflowInterface == null ) {
		//                _workflowInterface = createFolderTreeNode(sProcessInterface,
		//                    "module_folder_closed");
		//            } else {
		//                if ( _workflowInterface.Nodes.Count > 0 && !_rootNode.Nodes.Contains(_workflowInterface) ) {
		//                    if ( worker != null ) {
		//                        worker.ReportProgress(0, new WorkerState(Action.Add, _rootNode, _workflowInterface));
		//                    } else {
		//                        _rootNode.Nodes.Add(_workflowInterface);
		//                    }
		//                }
		//            }
		//            break;
		//            #endregion
		//        case FolderType.HumanActivities:
		//            #region Human Activities
		//            if ( _humanActivities == null ) {
		//                _humanActivities = createFolderTreeNode(sHumandActivitiesFolder,
		//                    "module_folder_closed");
		//            } else {
		//                if ( _humanActivities.Nodes.Count > 0 && !_rootNode.Nodes.Contains(_humanActivities) ) {
		//                    if ( worker != null ) {
		//                        worker.ReportProgress(0, new WorkerState(Action.Add, _rootNode, _humanActivities));
		//                    } else {
		//                        _rootNode.Nodes.Add(_humanActivities);
		//                    }
		//                }
		//            }
		//            break;
		//            #endregion
		//        case FolderType.WebServices:
		//            #region Web Services
		//            if ( _webservices == null ) {
		//                _webservices = createFolderTreeNode(sWebServicesFolder,
		//                    "folder_closed_webservices");
		//            } else {
		//                if ( _webservices.Nodes.Count > 0 && !_rootNode.Nodes.Contains(_webservices) ) {
		//                    if ( worker != null ) {
		//                        worker.ReportProgress(0, new WorkerState(Action.Add, _rootNode, _webservices));
		//                    } else {
		//                        _rootNode.Nodes.Add(_webservices);
		//                    }
		//                }
		//            }
		//            break;
		//            #endregion
		//        case FolderType.Nouns:
		//            #region Nouns
		//            if ( _nouns == null ) {
		//                _nouns = createFolderTreeNode(sNounsFolder,
		//                    "vocab_folder_closed");
		//            } else {
		//                if ( _nouns.Nodes.Count > 0 && !_rootNode.Nodes.Contains(_nouns) ) {
		//                    if ( worker != null ) {
		//                        worker.ReportProgress(0, new WorkerState(Action.Add, _rootNode, _nouns));
		//                    } else {
		//                        _rootNode.Nodes.Add(_nouns);
		//                    }
		//                }
		//            }
		//            break;
		//            #endregion
		//        default:
		//            break;
		//    }
		//}

		//#region protected override Fields
		//protected override delegate void VoidAction();
		//protected override TreeNode _rootNode = null;
		//RepositoryItemBaseEx _repItem = null;
		//BackgroundWorker worker = new BackgroundWorker();
		//protected override ContextMenuStrip _contextMenu = null;
		//protected override ContextMenuStrip _refreshMenu = null;
		//#region Folders
		//protected override TreeNode _nouns = null;
		//protected override TreeNode _capabilities = null;
		//protected override TreeNode _processes = null;
		//protected override TreeNode _processesBP = null;
		//protected override TreeNode _processesMashup = null;
		//protected override TreeNode _processesComposite = null;
		//protected override TreeNode _businessObjects = null;
		//protected override TreeNode _rules = null;
		//protected override TreeNode _logicalMethods = null;
		//protected override TreeNode _workflowInterface = null;
		//protected override TreeNode _webservices = null;
		//protected override TreeNode _humanActivities = null;
		//#endregion
		//#endregion

		//#region Protected Methods
		//protected override void OnBeforeExpand(TreeViewCancelEventArgs e)
		//{
		//    base.OnBeforeExpand(e);
		//    if ( e.Node != _rootNode && e.Node.Tag != null ) {
		//        if ( worker.IsBusy ) {
		//            worker.ReportProgress(0, new WorkerState(Action.EnqueueExpand, e.Node));
		//        } else {
		//            worker.RunWorkerAsync(BackgroundWorker worker, e.Node.Nodes);
		//        }
		//    }
		//}
		//#endregion

		//#region Public Properties
		//public RepositoryItemBaseEx RepositoryItem
		//{
		//    get { return _repItem; }
		//    set
		//    {
		//        _repItem = value;
		//        if ( _repItem != null ) load();
		//    }
		//}
		//#endregion
	}
}